from PyQt6.QtWidgets import QAbstractButton, QVBoxLayout, QPushButton, QLabel
from PyQt6 import QtGui
from PyQt6.QtCore import QSize, Qt


class IconButton(QPushButton):
    """
    自定义按钮类，从抽象按钮类中继承
    """

    def __init__(self, icon_path, text, parent=None):
        super(IconButton, self).__init__(parent)

        button_layout = QVBoxLayout(self)

        icon = QtGui.QIcon(QtGui.QPixmap(icon_path))
        self.setMinimumSize(40, 60)
        self.setMaximumSize(80, 100)

        button_layout.setContentsMargins(9,9,9,9)
        button_layout.setSpacing(9)

        icon_label = QLabel()
        icon_label.setPixmap(icon.pixmap(QSize(40, 40)))
        icon_label.setAlignment(Qt.AlignmentFlag.AlignCenter)

        text_label = QLabel(text)
        text_label.setAlignment(Qt.AlignmentFlag.AlignCenter)

        button_layout.addWidget(icon_label)
        button_layout.addWidget(text_label)

        """
        self.setIcon(icon)

        self.setIconSize(QSize(64, 64))

        self.setText(text)

        self.setFlat(True)

        self.setStyleSheet("QPushButton { text-align: center; }")
        self.setMinimumSize(80, 80)
        """


